package com.ruoyi.neusoft.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.neusoft.domain.AiIdentifyModelCheckT;
import com.ruoyi.neusoft.mapper.AiIdentifyModelCheckTMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.neusoft.mapper.AiIdentifyCollectionTMapper;
import com.ruoyi.neusoft.domain.AiIdentifyCollectionT;
import com.ruoyi.neusoft.service.IAiIdentifyCollectionTService;
import com.ruoyi.common.core.text.Convert;

/**
 * AI智能识别数据集Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-04-17
 */
@Service
public class AiIdentifyCollectionTServiceImpl implements IAiIdentifyCollectionTService 
{
    @Autowired
    private AiIdentifyCollectionTMapper aiIdentifyCollectionTMapper;


    @Autowired
    private AiIdentifyModelCheckTMapper checkTMapper;

    /**
     * 查询AI智能识别数据集
     * 
     * @param collectionId AI智能识别数据集主键
     * @return AI智能识别数据集
     */
    @Override
    public AiIdentifyCollectionT selectAiIdentifyCollectionTByCollectionId(Long collectionId)
    {
        AiIdentifyCollectionT collectionT = aiIdentifyCollectionTMapper.selectAiIdentifyCollectionTByCollectionId(collectionId);
        dealData(collectionT);
        return collectionT;
    }

    /**
     * 查询AI智能识别数据集列表
     * 
     * @param aiIdentifyCollectionT AI智能识别数据集
     * @return AI智能识别数据集
     */
    @Override
    public List<AiIdentifyCollectionT> selectAiIdentifyCollectionTList(AiIdentifyCollectionT aiIdentifyCollectionT)
    {
        List<AiIdentifyCollectionT> aiIdentifyCollectionTS = aiIdentifyCollectionTMapper.selectAiIdentifyCollectionTList(aiIdentifyCollectionT);
        aiIdentifyCollectionTS.forEach(collectionT->{
            dealData(collectionT);
        });

        return aiIdentifyCollectionTS;
    }

    /**
     * 新增AI智能识别数据集
     * 
     * @param aiIdentifyCollectionT AI智能识别数据集
     * @return 结果
     */
    @Override
    public int insertAiIdentifyCollectionT(AiIdentifyCollectionT aiIdentifyCollectionT)
    {
        aiIdentifyCollectionT.setCreateTime(DateUtils.getNowDate());
        return aiIdentifyCollectionTMapper.insertAiIdentifyCollectionT(aiIdentifyCollectionT);
    }

    /**
     * 修改AI智能识别数据集
     * 
     * @param aiIdentifyCollectionT AI智能识别数据集
     * @return 结果
     */
    @Override
    public int updateAiIdentifyCollectionT(AiIdentifyCollectionT aiIdentifyCollectionT)
    {
        aiIdentifyCollectionT.setUpdateTime(DateUtils.getNowDate());
        return aiIdentifyCollectionTMapper.updateAiIdentifyCollectionT(aiIdentifyCollectionT);
    }

    /**
     * 批量删除AI智能识别数据集
     * 
     * @param collectionIds 需要删除的AI智能识别数据集主键
     * @return 结果
     */
    @Override
    public int deleteAiIdentifyCollectionTByCollectionIds(String collectionIds)
    {
        return aiIdentifyCollectionTMapper.deleteAiIdentifyCollectionTByCollectionIds(Convert.toStrArray(collectionIds));
    }

    /**
     * 删除AI智能识别数据集信息
     * 
     * @param collectionId AI智能识别数据集主键
     * @return 结果
     */
    @Override
    public int deleteAiIdentifyCollectionTByCollectionId(Long collectionId)
    {
        return aiIdentifyCollectionTMapper.deleteAiIdentifyCollectionTByCollectionId(collectionId);
    }

    private void dealData(AiIdentifyCollectionT aiIdentifyCollectionT){
        Long modelId = aiIdentifyCollectionT.getModelId();
        String url = checkTMapper.selectOne(modelId);
        if(StringUtils.isNotEmpty(url)){
            aiIdentifyCollectionT.setCheckResourcePath(url);
        }


    }
}
